#json !/usr/bin/env python
#-*- coding:utf-8 -*-

import os
import sys
import datetime
reload(sys) 
sys.setdefaultencoding('utf8')
import time
import MySQLdb
sys.path.insert(0,'/home/liuyue/svn/wan/')
sys.path.insert(0,'/opt/web/')
sys.path.insert(0,'/opt/wanalytics/')
from Tools import connectMySQL




def TotalArea():
    
    #_datesql = " "
    #数据库连接
    try:
        db = connectMySQL.connMySQL("stat")
    except MySQLdb.Error, e:
        resultStr = '{"status": "failed", "code": "4001", "str": "connect database failed"}'
        return resultStr
    db.autocommit(True)
    c = db.cursor()
    
    c.execute("SHOW FULL PROCESSLIST")  
    result = c.fetchall()
    
    for x in result:
        pid = x[0]
        ss = x[4]
        print pid,ss
        if ss == "Sleep":
            sql = "KILL %s" % pid
            c.execute(sql)
    
    c.close()
    db.close()
    
    

    





if __name__ == '__main__':
    cmd = ''
    if len(sys.argv) == 2:
        cmd = sys.argv[1]
    TotalArea()
    print "done!"

